package com.example.electronicmall.service.impl;

import com.example.electronicmall.dao.UserDao;
import com.example.electronicmall.service.UserService;
import com.example.electronicmall.to.UserTo;
import com.example.electronicmall.utils.PageUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.example.electronicmall.entity.UserEntity;


@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        return null;
    }

    @Override
    public void register(UserTo userTo) {
        UserEntity userEntity = new UserEntity();
        BeanUtils.copyProperties(userTo, userEntity);
        Date date = new Date();
        userEntity.setCreatedAt(date);
        userEntity.setUpdatedAt(date);
        this.baseMapper.insert(userEntity);
    }

    @Override
    public UserEntity login(String username, String password) {
        return this.baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("username", username).eq("password", password));
    }

}